﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _022
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] arr1;//声明一个整型数组
            arr1 = new int[5];//初始化数组arr1
            double[] arr2;
            arr2 = new double[3];
            int[] arr3 = new int[3];
            arr3[0] = 1;
            arr3[1] = 2;
            arr3[2] = 3;
            int[] arr4 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            double[] arr5 = { 22.3, 23, 1, 123.34 };
            int[] arr6 = new int[3] { 0, 1, 2 };
            double[] arr7 = new double[2] { 0.1, 0.3};
            int[] arr8 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[] arr9 = arr8;
            int a = arr9[0];
            Console.WriteLine("a的值为：{0}",a);
            for(int i=0;i<10;i++)
            {
                Console.WriteLine("arr[{0}]={1} ", i, arr9[i]);
            }
            int index = 0;
            foreach(int i in arr9)
            {
                Console.WriteLine("arr[{0}]={1}",index,i);
                index++;
            }
            int[,] arr10 = new int[3, 3];//声明一个二维数组
            int[,,] arr11 = new int[3, 3, 3];//声明一个三维数组
            int[,] arr12 = new int[3, 4] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 } };
            int[,] arr13 = new int[,] { { 12, 13, 14, 15 }, { 16, 17, 18, 19 }, { 20, 21, 22, 23 } };
            int[,] arr14 = { { 24, 25, 26, 27 }, { 28, 29, 30, 31 }, { 32, 33, 34, 35 } };
            int b = arr14[1, 0];
            int c = arr14[2, 3];//矩阵，可以理解为行列关系
            Console.WriteLine(b);
            Console.WriteLine(c);
            int[][] arr15 = new int[3][];//定义一个交错数组
            arr15[0] = new int[] { 0, 1, 2, 3 };
            arr15[1] = new int[] { 1, 2 };
            arr15[2] = new int[] { 2, 3, 4, 5 };
            int[][] arr16 = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 7 }, new int[] { 11, 23 } };
            int[][] arr17 = { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } };
            int e = arr17[2][2];
            int[][,] arr18 = new int[3][,] { new int[,] { { 1, 2 }, { 3, 4 } }, new int[,] { { 5, 6 }, { 7, 8 }, { 9, 10 } }, new int[,] { { 11, 12 }, { 13, 14 }, { 15, 16 } } };
            int f = arr18[0][0, 1];
            Console.WriteLine("第一个数组的第一行第二个：答案为2：{0}",f);
            Console.WriteLine(e);
            arr17[2][1] = 0;
            int[][] arr19 = new int[3][] { new int[] { 11, 12, 13, 14, 15 }, new int[] { 16, 17, 18, 19, 20, 21, 22 }, new int[] { 23, 24 } };
            //遍历多维数组
            for(int i=0;i<arr19.Length;i++)
            {
                for(int j = 0; j < arr19[i].Length;j++)
                {
                    Console.Write(arr19[i][j] + "  ");
                }
                Console.WriteLine();
            }
            string[] names = { "小明", "小红", "小猪" };
            string[] course = { "语文", "数学", "英语" };
            int[][] arr20 = { new int[] { 98, 99, 100 }, new int[] { 50, 60, 70 }, new int[] { 88, 98, 87 } };
            for (int i=0;i<names.Length;i++)
            {
                string str = "";
                for(int j = 0; j < arr20[i].Length;j++)
                {
                    str += course[j] + "" + arr20[i][j] + ",";
                }
                Console.WriteLine("{0}的成绩为：{1}", names[i],str);
            }
            Program Obj = new Program();
            string str1 = Obj.getSum(1, 2, 3, 4, 5, 6);
            Console.WriteLine(str1);
            int[] arr21 = { 7, 8, 9, 10, 11 };
            string str2 = Obj.getSum(arr21);
            Console.WriteLine(str2);
            //创建一个数组并赋值
            int[] arr22 = new int[6] { 1, 2, 3, 4, 5, 6 };
            //创建一个空数组
            int[] arr23 = new int[6];
            //获取数组的长度
            Console.WriteLine("数组arr22的长度为：" + arr22.Length);
            //为数组排序
            Array.Sort(arr22);
            Console.Write("排序后的数组arr22为：");
            //打印排序后的arr22
            PrintArray(arr22);
            //查找数组元素的索引
            Console.WriteLine("\n数组arr中值为29的元素的索引："+Array.IndexOf(arr23,29));
            //拷贝arr22到arr23数组
            Array.Copy(arr22, arr23, arr22.Length);
            Console.Write("打印数组arr23:");
            //打印数组arr23
            PrintArray(arr23);
            Array.Reverse(arr22);
            Console.Write("\n反序排列数组arr22:");
            PrintArray(arr22);

            Console.ReadLine();
            Console.ReadKey();
        }
        static void PrintArray(int[]arr22)
        {
            foreach(object elem in arr22)
            {
                Console.Write(elem + " ");
            }   
        }
        public string getSum (params int[] arr21)
        {
            int sum = 0;
            string str = "";
            foreach(int i in arr21)
            {
                sum += i;
                str += "+" + i + "";
            }
            str = str.Trim('+');
            str += "=" + sum;
            return str;
        }
    
    }
}
